package logic

import (
	"context"
	"doctor-medicine-system/dockerrpc/dockerrpc"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMedicineUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineUpdateLogic {
	return &MedicineUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MedicineUpdateLogic) MedicineUpdate(req *types.MedicineUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	update, err := l.svcCtx.DockerRpc.MedicineUpdate(l.ctx, &dockerrpc.MedicineUpdateRequest{
		MedicineId: int64(req.MedicineId),
		Name:       req.Name,
		Style:      req.Style,
		Address:    req.Address,
		Good:       req.Good,
		Num:        req.Num,
		Work:       req.Work,
		DockerId:   int64(req.DockerId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    update,
	}, nil
}
